package com.yupi.yuaiagent.config;

import com.yupi.yuaiagent.rag.HappyAppDocumentLoader;
import com.yupi.yuaiagent.rag.MyKeywordEnricher;
import com.yupi.yuaiagent.rag.MyTokenTextSplitter;
import jakarta.annotation.Resource;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Configuration
public class HappyAppVectorStoreConfig {

    @Resource
    HappyAppDocumentLoader happyAppDocumentLoader;

    @Resource
    MyTokenTextSplitter myTokenTextSplitter;

    @Resource
    MyKeywordEnricher myKeywordEnricher;

    @Bean
    VectorStore happyAppVectorStore(@Qualifier("dashscopeEmbeddingModel") EmbeddingModel embeddingModel) {
        SimpleVectorStore simpleVectorStore = SimpleVectorStore.builder(embeddingModel)
                .build();
        //读取本地情感专家的文档
        List<Document> documents = happyAppDocumentLoader.loadMarkdownDocuments();

        //
        List<Document> splitedDocuments = myTokenTextSplitter.splitCustomized(documents);
        simpleVectorStore.add(documents);
        return simpleVectorStore;

    }

    //private void etl() {
        //

    //
    // }
}
